<template>
  <div>
    <h2>注册账号</h2>
    <input type="text" v-model.lazy="uname">
    <span>{{msg}} </span>

  </div>
</template>

<script>
import axios from 'axios'
export default {
  data() {
    return {
      uname: '',
      msg: ''
    }
  },
  // 侦听器函数，要写到 watch 里面。这是固定的
  watch: {
    // 被侦听的数据 (新的值, 原来的值) {  .......  }
    async uname(newVal) {
      // console.log(newVal, oldVal)
      if (newVal === '') return (this.msg = '')
      const result = await axios.get('http://www.itcbc.com:3006/api/finduser/' + newVal)
      this.msg = result.data.message
    }
  }
}
</script>

<style>

</style>